import {createRouter, createWebHistory} from 'vue-router'

const routes = [
  {
    path: '',
    redirect: '/welcome'
  },
  {
    path: '/',
    name: 'Main',
    component: () => import('../views/Main.vue'),
    // meta: {
    //   loginRequired: true
    // },
    children: [
      {
        path: 'welcome',
        name: 'Welcome',
        component: () => import('@/views/main/Welcome.vue'),
        meta: {title: '首页'}
      },
      {
          path: 'member',
          name: 'Member',
          children: [
              {
                path: 'ticket',
                name: 'Ticket',
                component: () => import('../views/member/Ticket.vue'),
                meta: {title: '车票管理'}
              },
          ]
      },
        {
        path: 'business',
        name: 'Business',
        children: [
          {
            path: 'confirm-order',
            name: 'ConfirmOrder',
            component: () => import('../views/business/ConfirmOrder.vue'),
            meta: {title: '订单信息'}
          },
          {
            path: 'daily-train-ticket',
            name: 'DailyTrainTicket',
            component: () => import('../views/business/DailyTrainTicket.vue'),
            meta: {title: '余票信息'}
          },
          {
            path: 'daily-train',
            name: 'DailyTrain',
            component: () => import('../views/business/DailyTrain.vue'),
            meta: {title: '每日车次管理'}
          },
          {
            path: 'daily-train-station',
            name: 'DailyTrainStation',
            component: () => import('../views/business/DailyTrainStation.vue'),
            meta: {title: '每日停靠站管理'}
          },
          {
            path: 'daily-train-carriage',
            name: 'DailyTrainCarriage',
            component: () => import('../views/business/DailyTrainCarriage.vue'),
            meta: {title: '每日车厢管理'}
          },
          {
            path: 'daily-train-seat',
            name: 'DailyTrainSeat',
            component: () => import('../views/business/DailyTrainSeat.vue'),
            meta: {title: '每日座位管理'}
          }
        ]
      },
      {
        path: 'base',
        name: 'Base',
        children: [
          {
            path: 'station',
            name: 'Station',
            component: () => import('../views/train/Station.vue'),
            meta: {title: '车站管理'}
          },
          {
            path: 'train',
            name: 'Train',
            component: () => import('../views/train/Train.vue'),
            meta: {title: '车次管理'}
          },
          {
            path: 'train-station',
            name: 'TrainStation',
            component: () => import('../views/train/TrainStation.vue'),
            meta: {title: '停靠站管理'}
          },
          {
            path: 'train-carriage',
            name: 'TrainCarriage',
            component: () => import('../views/train/TrainCarriage.vue'),
            meta: {title: '车厢管理'}
          },
          {
            path: 'train-seat',
            name: 'TrainSeat',
            component: () => import('../views/train/TrainSeat.vue'),
            meta: {title: '座位管理'}
          }
        ]
      },
      {
        path: 'batch/',
        name: 'Batch',
        children: [{
          path: 'job',
          name: 'Job',
          component: () => import('../views/batch/Job.vue'),
          meta: {title: '任务管理'}
        }]
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue'),
    meta: {title: '登录'}
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 路由拦截器
router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title} | 12306 控台`
  // // 要不要对meta.loginRequire属性做监控拦截
  // const isLogin = to.matched.some(item => item.meta.loginRequired)
  // if (isLogin) {
  //   const _member = store.state.member;
  //   if (!_member.token) {
  //     notification.error({ description: "未登录或登录超时" });
  //     next('/login');
  //   } else {
  //     next();
  //   }
  // } else {
  //   next();
  // }
  next();
})


export default router
